<?php
session_start();
$_SESSION['debug'] = false;
if($_SESSION['debug']){
	$_SESSION['userdata']['username']= "reader";
	$_SESSION['userdata']['rank']= "4";
	$_SESSION['auth'] = true;
	$_SESSION['rule'] = "READER";
}
if ($_SESSION['auth'] != true || $_SESSION['rule'] != "READER") {
	$currUrl = 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
	header("location:$currUrl/login.html");
	echo "please login.";
	echo "<br>redirecting...";
	exit();
}

include('includes/reader_lib.php');

$channel = get_rss();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Reader</title>
<link href="itelement.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
if(!empty($channel)) {
	foreach($channel as $c) {
		echo '<link rel="alternate" type="application/rss+xml" title="' . $c['title'] . '" href="rss.php?channel_id=' . $c['id'] . '" />';
		echo "\n";
	}
}
?>
<script src="script/jquery.js"></script>
<script language="javascript" type="text/javascript">
var MOZILLA = (document.getElementById?true:false);
var IE = (document.all?true:false); 
$(document).ready (
	function () {
		$('.tab').click(
			function(event){
				$('.selected-tab').removeClass('selected-tab').addClass('tab');
				$(this).removeClass('tab').addClass('selected-tab');
			}
		);
		$('.selected-tab').click(
			function(event){
				$('.selected-tab').removeClass('selected-tab').addClass('tab');
				$(this).removeClass('tab').addClass('selected-tab');
			}
		);
		//alert($('.tab').height());
		var headerHeight = 55;
		//init 
		if(IE){
			document.getElementById('main-right-box').style.height=($(window).height()-headerHeight-10)+'px'; 
		}else{
			headerHeight = $('#tabs').height()+$('#header').height()+5;
			$('#main-right-box').css('height',($(window).height()-headerHeight)+'px');
		}
		//handle window resize
		$(window).resize(function(){
		if(IE){
			document.getElementById('main-right-box').style.height=($(window).height()-headerHeight-10)+'px'; 
		}else{
			headerHeight = $('#tabs').height()+$('#header').height()+5;
			$('#main-right-box').height(($(window).height()-headerHeight)+'px');
			//alert($('#main-right-box').height());
		}
		});
	}
);
</script>
</head>
<body>
<div class="itelement" id="header">IT Element</div>
<div class="main">
  <div id="tabs">
    <div class="selected-tab"><a href="#" onClick="document.getElementById('main-right-box').src='reader_read_items.php'"> Subscribed Channel</a></div>
    <div class="tab"><a href="#" onClick="document.getElementById('main-right-box').src='reader_available.php'"> Available Channel</a></div>
	<div class="tab"><a href="#" onClick="document.getElementById('main-right-box').src='add_ext_channel.php'"> Add External Channel</a></div>
    <div class="tab"><a href="#" onClick="document.getElementById('main-right-box').src='reader_setting.php'"> Setting</a></div>	
    <!--<div class="tab" id="sql"></div> -->
    <div style="clear:both "></div>
  </div>
  <iframe width="100%" height="100%" id="main-right-box" frameborder="0" src="reader_read_items.php"></iframe>
</div>
<script src="script/update_channel.js"></script>
</body>
</html>